package com.wythe.mall.activity;

import android.content.Intent;
import android.os.Bundle;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.support.v7.widget.AppCompatEditText;
import android.support.v7.widget.AppCompatImageView;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.widget.TextView;

import com.wythe.mall.R;
import com.wythe.mall.adapter.MyFragmentPagerAdapter;
import com.wythe.mall.base.BaseActivity;
import com.wythe.mall.ui.OrderFragment;

import java.util.ArrayList;
import java.util.List;

public class OrderActivity extends BaseActivity {

    private TabLayout mainTabLayout;
    private ViewPager mainViewPager;
    private int mCurrentPage = 0;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_order_order);
        Bundle bundle = getIntent().getExtras();
        if (bundle != null) {
            mCurrentPage = bundle.getInt("id");
        }
        initView();
        initData();
    }
    public void initView() {
        findViewById(R.id.title_left_button).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                finish();
            }
        });
        ((TextView) findViewById(R.id.titleText)).setText("我的订单");
        mainTabLayout = (TabLayout) findViewById(R.id.mainTabLayout);
        mainViewPager = (ViewPager) findViewById(R.id.mainViewPager);

    }
    public void initData() {

        List<String> titleList = new ArrayList<>();
        titleList.add("全部");
        titleList.add("待付款");
        titleList.add("待发货");
        titleList.add("待收货");
        titleList.add("待评价");

        List<Fragment> mFragments = new ArrayList<>();
        mFragments.add(OrderFragment.getInstance(0));
        mFragments.add(OrderFragment.getInstance(1));
        mFragments.add(OrderFragment.getInstance(3));
        mFragments.add(OrderFragment.getInstance(5));
        mFragments.add(OrderFragment.getInstance(7));
        mainTabLayout.setTabMode(TabLayout.MODE_FIXED);
        mainViewPager.setAdapter(new MyFragmentPagerAdapter(getSupportFragmentManager(),titleList, mFragments));
        mainViewPager.setCurrentItem(mCurrentPage);
        mainViewPager.setOffscreenPageLimit(titleList.size() - 1);
        mainTabLayout.setupWithViewPager(mainViewPager);
        //为ViewPager设置页面变化的监控
        mainViewPager.addOnPageChangeListener(onPageChangeListener);
    }

    private ViewPager.OnPageChangeListener onPageChangeListener = new ViewPager.OnPageChangeListener() {

        @Override
        public void onPageSelected(int arg0) {

        }

        @Override
        public void onPageScrolled(int arg0, float arg1, int arg2) {
            // TODO Auto-generated method stub

        }

        @Override
        public void onPageScrollStateChanged(int arg0) {
            // TODO Auto-generated method stub

        }
    };

}
